################################################################################
# pslint - utility to pre-check personal statements for common mistakes        #
# and wasted space before input onto a form                                    #
#                                                                              #
#                                Makefile                                      #
#                                                                              #
# inspired by Void Linux's xlint (from xtools)                                 #
#                                                                              #
# (C) 2016 William Obiri-Danso                                                 #
#                                                                              #
# Licensed under the Apache License, Version 2.0 (the "License");              #
# you may not use this file except in compliance with the License.             #
# You may obtain a copy of the License at                                      #
#                                                                              #
#     http://www.apache.org/licenses/LICENSE-2.0                               #
#                                                                              #
# Unless required by applicable law or agreed to in writing, software          #
# distributed under the License is distributed on an "AS IS" BASIS,            #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.     #
# See the License for the specific language governing permissions and          #
# limitations under the License.                                               #
################################################################################ 

CXX = g++ # All platforms with GCC (could replace with clang, not tested however.)
CXX_MIN32 = i686-w64-mingw32-g++ # 32-bit (legacy, windoze-32 on mingw)
CXX_MIN64 = x86_64-w64-mingw32-g++ # 64-bit (recommended, windoze-64 on mingw)
CXXFLAGS = -std=c++11 -O2 -Wall -g -static # common to all compilers
NATIVE_32BIT = -m32 # 32-bit build support on unix/native systems
VERSION = 3# for release branding

all: native native-32 mingw

mingw: mingw-32 mingw-64

native:
	@echo "*** Building pslint for native-64 ***"
	$(CXX) $(CXXFLAGS) pslint.cpp -o pslint
	@echo "*** Done! ***"
	
native-32:
	@echo "*** Building pslint for native-32 ***"
	$(CXX) $(CXXFLAGS) $(NATIVE_32BIT) pslint.cpp -o pslint
	@echo "*** Done! ***"
	
mingw-32:
	@echo "*** Building pslint for mingw32 ***"
	$(CXX_MIN32) $(CXXFLAGS) pslint.cpp -o pslint-32.exe
	@echo "*** Done! ***"

mingw-64:
	@echo "*** Building pslint for mingw64 ***"
	$(CXX_MIN64) $(CXXFLAGS) pslint.cpp -o pslint-64.exe
	@echo "*** Done! ***"
	
install: native
	@echo "*** Installing pslint ***"
	install -Dm755 pslint /usr/bin
	@echo "*** Done! ***"
	
uninstall: 
	@echo "*** Uninstalling pslint ***"
	rm /usr/bin/pslint
	@echo "*** Done! ***"
	
release: native mingw
	@echo "*** Creating release binaries ***"
	@mkdir rel
	tar cvJf rel/pslint-$(VERSION)-linux.tar.xz pslint Readme.md LICENSE
	zip rel/pslint-$(VERSION)-windows.zip pslint-*.exe Readme.md LICENSE
	@echo "*** Done! ***"
    
clean:
	@echo "*** Removing compiled files ***"
	rm pslint
	rm pslint-32.exe 
	rm pslint-64.exe
	rm -rf rel
	@echo "*** Done! ***"
    
